import { reqGoodDetailInfoData } from "@/api";
const state = {
  goodDetailInfo: {},
};
const actions = {
  async getGoodDetailInfoData({ commit }, id) {
    const result = await reqGoodDetailInfoData(id);
    if (result.code === 200) {
      commit(SAVE_GOOD_DETAIL_INFO_DATA, result.data);
    } else {
      console.log(result.message);
    }
  },
};

const mutations = {
  SAVE_GOOD_DETAIL_INFO_DATA(state, payload) {
    state.goodDetailInfo = payload;
  },
};

const getters = {
  categoryView(state) {
    return state.goodDetailInfo.categoryView || {};
  },
  skuInfo(state) {
    return state.goodDetailInfo.skuInfo || {};
  },
  supSaleAttrList(state) {
    return state.goodDetailInfo.supSaleAttrList || [];
  },
};

export default {
  state,
  actions,
  mutations,
  getters,
};
